Using Tile Maps
In game development, tile maps are a common way to construct scenes. This article will introduce how to create tile maps using Tiled Editor, how to load and render these maps using the TileNode class in the Dora SSR game engine, and how to read layered data from the maps.
1. Introduction to Tiled Editor
Tiled Editor is a free, open-source, and powerful tile map editor. It supports various map formats and layers, making it convenient to create complex game scenes. Key features include:
- Multi-platform support: Runs on Windows, macOS, Linux, and other operating systems.
- Flexible layer system: Supports multi-layer map editing, including tile layers, object layers, and image layers.
- Rich export formats: Supports exporting to JSON, XML, TMX, and other formats for easy integration with various game engines.
2. Loading and Rendering Tile Maps with TileNode
2.1 Preparation
First, ensure that Tiled Editor is installed and you have created a tile map exported as a TMX (XML format) file. For example, we have a map file named platform.tmx
.
2.2 Creating a TileNode Instance
In your Lua script, first load the TileNode
module, then create a TileNode
object.
- Lua
- Teal
- TypeScript
- YueScript
local TileNode <const> = require("TileNode")
-- Load the entire map
local tmxNode = TileNode("TMX/platform.tmx")
local TileNode <const> = require("TileNode")
-- Load the entire map, including all layers
local tmxNode = TileNode("TMX/platform.tmx")
import { TileNode } from "Dora";
// Load the entire map, including all layers
const tmxNode = TileNode("TMX/platform.tmx");
_ENV = Dora
-- Load the entire map, including all layers
tmxNode = TileNode "TMX/platform.tmx"
If you want to load only specific layers, you can specify the layer name when creating the TileNode
:
- Lua
- Teal
- TypeScript
- YueScript
-- Load a specific layer
local tmxNode = TileNode("TMX/platform.tmx", "Far")
-- Load a specific layer
local tmxNode = TileNode("TMX/platform.tmx", "Far")
// Load a specific layer
const tmxNode = TileNode("TMX/platform.tmx", "Far");
-- Load a specific layer
tmxNode = TileNode "TMX/platform.tmx" "Far"
Or load multiple specific layers:
- Lua
- Teal
- TypeScript
- YueScript
-- Load multiple layers
local tmxNode = TileNode("TMX/platform.tmx", {"Far", "Near"})
-- Load multiple layers
local tmxNode = TileNode("TMX/platform.tmx", {"Far", "Near"})
// Load multiple layers
const tmxNode = TileNode("TMX/platform.tmx", ["Far", "Near"]);
-- Load multiple layers
tmxNode = TileNode "TMX/platform.tmx", ["Far", "Near"]